﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminCP/Layouts/Admin.Master" AutoEventWireup="true"
    CodeBehind="Products.aspx.cs" Inherits="MLM.AdminCP.Pages.Products" meta:resourcekey="PageResource1" %>

<%@ Import Namespace="MLM.AdminCP.Class" %>
<%@ Import Namespace="System" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Label runat="server" ID="lbShop" Text="Shop" meta:resourcekey="lbShopResource1"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div class="FillterProduct">
        <telerik:RadComboBox CssClass="rancombox2" runat="server" ID="RabCountry" DataTextField="Name"
            DataValueField="CountryID" DataSourceID="CountriesEds" AutoPostBack="True" EnableLoadOnDemand="True"
            Label="Select Country:" meta:resourcekey="RabCountryResource1">
            <HeaderTemplate>
                <ul>
                    <li style="list-style-type: none" class="col1">
                        <asp:Label ID="lbCountry" runat="server" Text="Country" meta:resourcekey="lbCountryResource1"></asp:Label></li>
                </ul>
            </HeaderTemplate>
        </telerik:RadComboBox>
        >>
        <telerik:RadComboBox CssClass="rancombox" runat="server" ID="RadUser" DataTextField="FullName"
            AllowCustomText="True" DataValueField="UserId" DataSourceID="DepoEds" AutoPostBack="True"
            EnableViewState="False" EmptyMessage="Select Depo" EnableLoadOnDemand="True"
            Label="Select Depo" meta:resourcekey="RadUserResource1">
            <HeaderTemplate>
                <ul>
                    <li style="list-style-type: none" class="col1">
                        <asp:Label runat="server" ID="lbDepo" Text="Depo" meta:resourcekey="lbDepoResource1"></asp:Label>
                    </li>
                </ul>
            </HeaderTemplate>
        </telerik:RadComboBox>
        <telerik:RadTextBox runat="server" ID="ProductNumberTxt" Label="Product Number" 
            Width="250px" meta:resourcekey="ProductNumberTxtResource1" />
        <input type="button" id="QuickOrderTxt" value="Order" class="CartOut" style="height: 25px; line-height: 25px;" />
        <script type="text/javascript">
            var MLM = {};
            MLM.PleaseSelectADepo = '<%=Resources.MLM.PleaseSelectADepo %>';
            MLM.PleaseInputAProductNumber = '<%=Resources.MLM.PleaseInputAProductNumber %>';
            MLM.ProductNotFound = '<%=Resources.MLM.ProductNotFound %>'
            MLM.AddToCartSuccess = '<%=Resources.MLM.AddToCartSuccess %>'
            $('#QuickOrderTxt').off('click').on('click', function () {
                var productNumber = $find('<%=ProductNumberTxt.ClientID %>').get_value();
                var depoId = '';
                try {
                    depoId = $find("<%=RadUser.ClientID %>").get_selectedItem().get_value();
                } catch (e) {
                    alert(MLM.PleaseSelectADepo);
                    return false;
                }
                if (productNumber == '') {
                    alert(MLM.PleaseInputAProductNumber);
                    return false;
                }
                if (isNaN(depoId)) {
                    alert(MLM.PleaseSelectADepo);
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: "/AdminCP/Pages/Products.aspx/GetProductIdByPNumber",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: "{'_productnumber':'" + productNumber + "','_depoid':'" + depoId + "'}",
                    success: function (msj) {
                        var item = parseInt(JSON.parse(msj.d));
                        if (item === 0) {
                            alert(MLM.ProductNotFound);
                        } else {
                            var ProducID = item;
                            var CountProduct = 1;
                            var CountryID = $(".HfCountryID").text();
                            var UserID = $(".HfUserID").text();
                            $.ajax({
                                type: "POST",
                                url: "/AdminCP/Pages/ShoppingCart.aspx/AddToCart",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                beforeSend: function () {
                                    $('.loadingstate').css("display", "inline-block");
                                    $('.loadingstate').html('<img src="/App_Themes/UIT/UITImages/vi-VN/loading7.gif" width="100" height="100" />');
                                },
                                data: "{'product':'" + ProducID + "','CountProduct':'" + CountProduct + "','CountryID':'" + CountryID + "','UserID':'" + UserID + "'}",
                                async: true,
                                success: function (msj) {
                                    if (msj.d > 0) {
                                        $('.loadingstate').css("display", "none");
                                        $.notify.success(MLM.AddToCartSuccess, {
                                            occupySpace: true,
                                            close: true,
                                            autoClose: 3000
                                        });
                                        $find('<%=ProductNumberTxt.ClientID %>').set_value('');
                                        $(".Total").text(msj.d);
                                    }
                                }
                            });
                        }
                    }
                });
            });
        </script>
    </div>
    <div id="Product">
        <%--DataSourceID="GroupProductEds"--%>
        <asp:ListView ID="ProductViews" runat="server" GroupItemCount="3" DataKeyNames="ProductBaseID"  OnPagePropertiesChanged="ProductViews_OnPagePropertiesChanged">
            <LayoutTemplate>
                <div runat="server" id="tblProducts" style="height: 800px">
                    <div runat="server" id="groupPlaceholder">
                    </div>
                    <div id="divPager">
                        <asp:DataPager runat="server" ID="DataPager" PageSize="9" PagedControlID="ProductViews"
                            OnPreRender="DataPager_PreRender">
                            <Fields>
                                <asp:NextPreviousPagerField ShowFirstPageButton="True" 
                                    ShowNextPageButton="False" meta:resourcekey="NextPreviousPagerFieldResource2" />
                                <asp:NumericPagerField meta:resourcekey="NumericPagerFieldResource1" />
                                <asp:NextPreviousPagerField ShowLastPageButton="True" 
                                    ShowPreviousPageButton="False" 
                                    meta:resourcekey="NextPreviousPagerFieldResource3" />
                            </Fields>
                        </asp:DataPager>
                    </div>
                </div>
            </LayoutTemplate>
            <GroupTemplate>
                <div runat="server" id="productRow">
                    <div runat="server" id="itemPlaceholder">
                    </div>
                </div>
            </GroupTemplate>
            <ItemTemplate>
                <div class="itemProduct">
                    <div class="Thumbitem">
                        <asp:Image ID="ProductImage" runat="server" ImageUrl='<%# Eval("ProductBas.ThumbImage") %>'
                            meta:resourcekey="ProductImageResource1" /><br />
                    </div>
                    <div class="Title">
                        <b>
                            <%# Eval("ProductBas.Name")%></b> (<%#Eval("ProductBas.ProductNumber")%>)
                    </div>
                    <div class="Price">
                        <asp:Label runat="server" ID="lbprice" Text="Price:" meta:resourcekey="lbpriceResource1"></asp:Label>
                        <h1>
                            <%# FormatPrice(Eval("ProductBas.Price"), RabCountry.SelectedValue.ToString().GetVATByCountryUser(), dtct, Eval("ProductBaseId"), RabCountry.SelectedValue.ToString())%>
                        </h1>
                    </div>
                    <div class="Price">
                         <asp:Label ID="Label1" runat="server" Text="Category:"></asp:Label>
                            <%#Eval("ProductBas.ProductCategory.Name")%>
                    </div>
                    <div class="BtBuy">
                        <telerik:RadNumericTextBox ShowSpinButtons="True" labelwidth="120px" runat="server"
                            CssClass="CountProduct" ID="CountProduct" Width="148px" Value="1" Culture="en-US"
                            LabelCssClass="" meta:resourcekey="CountProductResource1">
                            <NumberFormat GroupSeparator="" DecimalDigits="0" />
                        </telerik:RadNumericTextBox>
                        <a href="#" id="btnBuy" text="Buy" runat="server" causesvalidation="False" 
                            class="CartOut"  productid='<%#Eval("ProductBaseId") %>'>Buy</a>
                    </div>
                </div>
            </ItemTemplate>
        </asp:ListView>
        <asp:ListView ID="lvDepoProduct" runat="server" GroupItemCount="3" DataKeyNames="ProductBaseID">
            <LayoutTemplate>
                <div runat="server" id="tblProducts" style="height: 800px">
                    <div runat="server" id="groupPlaceholder">
                    </div>
                </div>
                <div id="divPager">
                    <asp:DataPager runat="server" ID="DataPagerDepo" PageSize="9" PagedControlID="lvDepoProduct"
                        OnPreRender="DataPagerDepo_PreRender">
                        <Fields>
                            <asp:NextPreviousPagerField ShowFirstPageButton="True" 
                                ShowNextPageButton="False" meta:resourcekey="NextPreviousPagerFieldResource4" />
                            <asp:NumericPagerField meta:resourcekey="NumericPagerFieldResource2" />
                            <asp:NextPreviousPagerField ShowLastPageButton="True" 
                                ShowPreviousPageButton="False" 
                                meta:resourcekey="NextPreviousPagerFieldResource5" />
                        </Fields>
                    </asp:DataPager>
            </LayoutTemplate>
            <GroupTemplate>
                <div runat="server" id="productRow">
                    <div runat="server" id="itemPlaceholder">
                    </div>
                </div>
            </GroupTemplate>
            <ItemTemplate>
                <div class="itemProduct">
                    <div class="Thumbitem">
                        <asp:Image ID="ProductImage" runat="server" ImageUrl='<%# Eval("ThumbImage") %>'
                            meta:resourcekey="ProductImageResource1" /><br />
                    </div>
                    <div class="Title">
                        <b>
                            <%# Eval("Name")%></b> (<%#Eval("ProductNumber") %>)
                    </div>
                    <div class="Price">
                        <asp:Label runat="server" ID="lbprice" Text="Price:" meta:resourcekey="lbpriceResource1"></asp:Label>
                        <h1>
                            <%# FormatPrice(Eval("Price"), RabCountry.SelectedValue.GetVATByCountryUser(), dtct, Eval("ProductBaseID"), RabCountry.SelectedValue)%></h1>
                    </div>
                    <div class="Price">
                        <asp:Label runat="server" Text="Category:"></asp:Label>
                        <%#Eval("ProductCategory.Name") %>
                    </div>
                    <div class="BtBuy">
                        <telerik:RadNumericTextBox ShowSpinButtons="True" labelwidth="120px" runat="server"
                            CssClass="CountProduct" ID="CountProduct" Width="148px" Value="1" Culture="en-US"
                            LabelCssClass="" meta:resourcekey="CountProductResource1">
                            <NumberFormat GroupSeparator="" DecimalDigits="0" />
                        </telerik:RadNumericTextBox>
                        <a href="#" id="btnBuy" text="Buy" runat="server" causesvalidation="False" 
                            class="CartOut"  productid='<%#Eval("ProductBaseId") %>'>Buy</a>
                    </div>
                </div>
            </ItemTemplate>
        </asp:ListView>
        <asp:Label runat="server" CssClass="HfCountryID" ID="HfCountryID" meta:resourcekey="HfCountryIDResource1"></asp:Label>
        <asp:Label runat="server" CssClass="HfUserID" ID="HfUserID" meta:resourcekey="HfUserIDResource1"></asp:Label>
    </div>
    <asp:EntityDataSource ID="CountriesEds" runat="server" ConnectionString="name=MLMDataContext"
        DefaultContainerName="MLMDataContext" EnableDelete="True" EnableFlattening="False"
        EnableInsert="True" EnableUpdate="True" EntitySetName="Countries" 
        EntityTypeFilter="" Select="">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="DepoEds" runat="server" ConnectionString="name=MLMDataContext"
        DefaultContainerName="MLMDataContext" EntitySetName="Users" Select="it.UserId,(it.FirstName +' '+ it.LastName) as FullName"
        
        Where="it.CountryID=@CountryIDParam &&(it.RoleID < @CurrentRoleId || @CurrentRoleId=1) && it.UserId!=@CurrentUserId" 
        EntityTypeFilter="">
        <WhereParameters>
            <asp:ControlParameter ControlID="RabCountry" Name="CountryIDParam" Type="Int64" PropertyName="SelectedValue" />
            <asp:CookieParameter Name="CurrentRoleId" Type="Int64" CookieName="CurrentUserRole" />
            <asp:CookieParameter Name="CurrentUserId" Type="Int64" CookieName="CurrentUserId" />
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:HiddenField ID="CurrentRoleID" runat="server" />
    <asp:UpdateProgress runat="server">
        <ProgressTemplate>
            <div id="loadingDiv" style="position: fixed; top: 50%; left: 50%; width: 200px; text-align: center;
                padding: 3px; border: solid 1px #ccc; background: #f1f1f1;">
                Loading data, please wait...</div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</asp:Content>
